/* 
 * song style definition
 *
 * Choi Jonghwan<saxboy@gmail.com>
 * 2006/04/23
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "songstyle.h"


SONGSTYLE songstyle_New(void)
{
	SONGSTYLE ss=NULL; 

	if ( (ss=(SONGSTYLE)malloc(sizeof(_SONGSTYLE))) != NULL)
	{
		memset(ss, 0, sizeof(_SONGSTYLE)); 
	}

	return ss; 
}

SONGSTYLE songstyle_NewWithStyle(const char *name)
{
	SONGSTYLE ss = songstyle_New(); 
	if (ss!=NULL) 
	{
		if ( songstyle_Load(ss, name) > 0 )
			return ss; 
	}

	songstyle_Delete(ss); 
	return NULL; 
}

int songstyle_Delete(SONGSTYLE ss)
{
	if (ss==NULL) return -1; 

	{
		int i=0; 

		for (i=0; i< ss->artist_count; i++)
			artist_Delete( ss->artists[i]); 
	}

	free(ss); 
	return 1; 
}


int songstyle_Load(SONGSTYLE ss, const char *name)
{
	if (ss==NULL) return -1; 
	if (name==NULL) return -1; 

	/* TODO: load it */

	/* jazz: temp... */
	{
		ARTIST a=NULL; 

		/* setup artists */

		/* FIXME:
		 * this is a design problem, 
		 * drummer should be added first 
		 * see export_abc
		 */
		a = artist_NewWithName("latin drummer"); 
		artist_SetInstrument(a, instrument_NewWithName("drum") ); 
		artist_SetArtistStyle(a, artiststyle_NewWithStyle("latindrum")); 
		//artist_SetArtistStyle(a, artiststyle_NewWithStyle("bebopdrum")); 
		a->b_is_drummer = 1; 

		songstyle_AddArtist(ss, a); 

		a = artist_NewWithName("latin bassist"); 
		artist_SetInstrument(a, instrument_NewWithName("bass") ); 
		//artist_SetArtistStyle(a, artiststyle_NewWithStyle("walkingbass")); 
		//artist_SetArtistStyle(a, artiststyle_NewWithStyle("latinbass")); 
		artist_SetArtistStyle(a, artiststyle_NewWithStyle("rockbass")); 
		songstyle_AddArtist(ss, a); 

#if 1
		a = artist_NewWithName("jazz saxophonist"); 
		artist_SetInstrument(a, instrument_NewWithName("saxophone") ); 
		artist_SetArtistStyle(a, artiststyle_NewWithStyle("melody")); 
		songstyle_AddArtist(ss, a); 
#endif

#if 0
		a = artist_NewWithName("jazz pianist"); 
		artist_SetInstrument(a, instrument_NewWithName("piano") ); 
		artist_SetArtistStyle(a, artiststyle_NewWithStyle("jazzpiano")); 
		songstyle_AddArtist(ss, a); 
#endif

	}

	return 1; 
}

int songstyle_GetArtistCount(SONGSTYLE ss)
{
	if (ss==NULL) return -1; 
	return ss->artist_count; 
}

ARTIST songstyle_GetArtist(SONGSTYLE ss, int i)
{
	if (ss==NULL) return NULL; 
	if (i<0) return NULL; 
	if (i>= ss->artist_count) return NULL; 

	return ss->artists[i]; 	
}

int songstyle_AddArtist(SONGSTYLE ss, ARTIST a) 
{
	if (ss==NULL) return -1; 
	if (a==NULL) return -1; 

	ss->artists[ ss->artist_count ] = a; 
	ss->artist_count++; 

	return 1; 
}
